import lodash from 'lodash'
import setting from './settings.js'
import { PLUGIN_PATH } from './function/function.js'

export function supportGuoba() {
    return {
        pluginInfo: {
            name: 'Bread-Shop',
            title: '面包商店',
            description: '面包商店配置中心',
            author: 'Tloml-Starry',
            authorLink: 'https://gitee.com/Tloml-Starry',
            link: 'https://gitee.com/Tloml-Starry/Bread-Shop',
            isV3: true,
            isV2: false,
            showInMenu: 'auto',
            icon: 'mdi:stove',
            iconColor: '#d19f56',
            iconPath: `${PLUGIN_PATH}/resources/image/breadRankingList/Bread.png`,
        },
        configInfo: {
            schemas: [
                {
                    component: 'Divider',
                    label: '基础设置'
                },
                {
                    field: 'config.bread_thing',
                    label: '自定义全局通用物品',
                    bottomHelpMessage: '除自定义群聊内的操作指令',
                    component: 'Input',
                    required: true,
                    componentProps: {
                        placeholder: '请输入自定义物品',
                    }
                },
                {
                    field: 'config.level_bread_num',
                    label: '升一级所需要的面包数量',
                    bottomHelpMessage: '设置升级需要面包数量（不建议低于吃面包上限）',
                    component: 'InputNumber',
                    required: true,
                    componentProps: {
                        min: 1,
                        max: 999,
                        placeholder: '请输入数量'
                    },
                },
                {
                    component: 'Divider',
                    label: '操作CD设置(单位: 秒)'
                },
                {
                    field: 'config.cd_buy',
                    label: '买的CD',
                    bottomHelpMessage: '设置买的CD',
                    component: 'InputNumber',
                    required: true,
                    componentProps: {
                        min: 1,
                        max: 99999,
                        placeholder: '请输入数字'
                    },
                },
                {
                    field: 'config.cd_eat',
                    label: '吃的CD',
                    bottomHelpMessage: '设置吃的CD',
                    component: 'InputNumber',
                    required: true,
                    componentProps: {
                        min: 1,
                        max: 99999,
                        placeholder: '请输入数字'
                    },
                },
                {
                    field: 'config.cd_rob',
                    label: '抢的CD',
                    bottomHelpMessage: '设置抢的CD',
                    component: 'InputNumber',
                    required: true,
                    componentProps: {
                        min: 1,
                        max: 99999,
                        placeholder: '请输入数字'
                    },
                },
                {
                    field: 'config.cd_give',
                    label: '送的CD',
                    bottomHelpMessage: '设置送的CD',
                    component: 'InputNumber',
                    required: true,
                    componentProps: {
                        min: 1,
                        max: 99999,
                        placeholder: '请输入数字'
                    },
                },
                {
                    field: 'config.cd_bet',
                    label: '赌的CD',
                    bottomHelpMessage: '设置赌的CD',
                    component: 'InputNumber',
                    required: true,
                    componentProps: {
                        min: 1,
                        max: 99999,
                        placeholder: '请输入数字'
                    },
                },
                {
                    component: 'Divider',
                    label: '操作操作上限'
                },
                {
                    field: 'config.max_buy',
                    label: '买的上限',
                    bottomHelpMessage: '设置买的最大数量',
                    component: 'InputNumber',
                    required: true,
                    componentProps: {
                        min: 1,
                        max: 99999,
                        placeholder: '请输入数字'
                    },
                },
                {
                    field: 'config.max_eat',
                    label: '吃的上限',
                    bottomHelpMessage: '设置吃的最大数量',
                    component: 'InputNumber',
                    required: true,
                    componentProps: {
                        min: 1,
                        max: 99999,
                        placeholder: '请输入数字'
                    },
                },
                {
                    field: 'config.max_rob',
                    label: '抢的上限',
                    bottomHelpMessage: '设置抢的最大数量',
                    component: 'InputNumber',
                    required: true,
                    componentProps: {
                        min: 1,
                        max: 99999,
                        placeholder: '请输入数字'
                    },
                },
                {
                    field: 'config.max_give',
                    label: '送的上限',
                    bottomHelpMessage: '设置送的最大数量',
                    component: 'InputNumber',
                    required: true,
                    componentProps: {
                        min: 1,
                        max: 99999,
                        placeholder: '请输入数字'
                    },
                },
                {
                    field: 'config.max_bet',
                    label: '赌的上限',
                    bottomHelpMessage: '设置赌的最大数量',
                    component: 'InputNumber',
                    required: true,
                    componentProps: {
                        min: 1,
                        max: 99999,
                        placeholder: '请输入数字'
                    },
                },
                { component: 'Divider', label: '操作操作下限' },
                {
                    field: 'config.min_buy',
                    label: '买的下限',
                    bottomHelpMessage: '设置买的最小数量',
                    component: 'InputNumber',
                    required: true,
                    componentProps: {
                        min: 1,
                        max: 99999,
                        placeholder: '请输入数字'
                    },
                }, {
                    field: 'config.min_eat',
                    label: '吃的下限',
                    bottomHelpMessage: '设置吃的最小数量',
                    component: 'InputNumber',
                    required: true,
                    componentProps: {
                        min: 1,
                        max: 99999,
                        placeholder: '请输入数字'
                    },
                }, {
                    field: 'config.min_rob',
                    label: '抢的下限',
                    bottomHelpMessage: '设置抢的最小数量',
                    component: 'InputNumber',
                    required: true,
                    componentProps: {
                        min: 1,
                        max: 99999,
                        placeholder: '请输入数字'
                    },
                }, {
                    field: 'config.min_give',
                    label: '送的下限',
                    bottomHelpMessage: '设置送的最小数量',
                    component: 'InputNumber',
                    required: true,
                    componentProps: {
                        min: 1,
                        max: 99999,
                        placeholder: '请输入数字'
                    },
                },
                {
                    field: 'config.min_bet',
                    label: '赌的下限',
                    bottomHelpMessage: '设置赌的最小数量',
                    component: 'InputNumber',
                    required: true,
                    componentProps: {
                        min: 1,
                        max: 99999,
                        placeholder: '请输入数字'
                    },
                },
                {
                    component: 'Divider',
                    label: '是否允许随机抢和送'
                },
                {
                    field: 'config.is_random_robbed',
                    label: '是否允许随机抢',
                    bottomHelpMessage: '是否允许未@人时随机抢面包',
                    component: 'Switch',
                },
                {
                    field: 'config.is_random_given',
                    label: '是否允许随机送',
                    bottomHelpMessage: '是否允许未@人时随机送面包',
                    component: 'Switch',
                }
            ],
            getConfigData() {
                return setting.merge()
            },
            setConfigData(data, { Result }) {
                let config = {}
                for (let [keyPath, value] of Object.entries(data)) {
                    lodash.set(config, keyPath, value)
                }
                config = lodash.merge({}, setting.merge, config)
                setting.analysis(config)
                return Result.ok({}, '保存成功~')
            }
        }
    }
}